/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.mobiwebinc.compconn.events.command;

/**
 *
 * @author suraj
 */
public class Decoder {
    public static int[] intParameters(String cmd) {
        String[] params = stringParameters(cmd);
        int[] pars = new int[params.length];
        for(int i=0;i<params.length;i++)
            pars[i] = Integer.parseInt(params[i]);
        return pars;
    }

    public static double[] doubleParameters(String cmd) {
        String[] params = stringParameters(cmd);
        double[] pars = new double[params.length];
        for(int i=0;i<params.length;i++)
            pars[i] = Double.parseDouble(params[i]);
        return pars;
    }

    public static String[] stringParameters(String cmd) {
        String[] parts = cmd.split(Command.DELIMITER);
        String[] params = new String[parts.length - 1];
        for(int i=1;i<parts.length;i++)
            params[i-1] = parts[i];
        return params;
    }

    public static String stringParameter(String cmd) {
        return cmd.indexOf(" ") > 0 ? cmd.substring(cmd.indexOf(" ")) : "";
    }
}
